#pragma once

#ifndef __GRAB_MANAGER_H__
#define __GRAB_MANAGER_H__

#include "Common.h"
#include "LogManager.h"
#include "InputHelper.h"

typedef struct
{
	int PixelsToScan;
	int SensibilityLevel;
	int StartAfterInterval;
	int StartAfterRandomInterval;
	int TryInterval;
	int ClicksPerTry;
	InputOptions InputOptions;
	vector<POINT> ScanCoordinates;
} GrabOptions;

// Helper for grab operations.
class GrabManager
{
public:
	// Start the grab manager.
	static void Start(GrabOptions& grabOptions);

	// Stop the grab manager.
	static void GrabManager::Stop();

private:
	static GrabManager m_instance;
	bool m_run, m_hooked, m_autoGrab, m_manualGrab, m_tryToCapture;
	int m_pixelsToScan, m_sensibilityLevel, m_startSleep, m_startAfterInterval, m_startAfterRandomInterval, m_tryInterval, m_clicksPerTry;
	vector<POINT> m_coordinates;
	vector<POINT> m_coordinatesToScan;
	HHOOK m_hHock;
	InputHelper m_inputHelper;

	// Construct GrabManager.
	GrabManager();

	// Finalize GrabManager.
	~GrabManager();

	// Load the options.
	void LoadOptions(GrabOptions& grabOptions);

	// Show the help.
	void ShowHelp();

	// Start the manual grab process.
	bool StartManualGrab();

	// Stop the manual grab process.
	bool StopManualGrab();

	// Switch the automatic grab process mode.
	bool SwitchAutoGrab();

	// Set the cursor position.
	void SetCursorPosition();

	// Get the cursor position.
	void GetCursorPosition();

	// Increase the number of pixels to scan.
	bool IncreasePixelsToScan();

	// Decrease the number of pixels to scan.
	bool DecreasePixelsToScan();

	// Raise the sensibility.
	void RaiseSensibilityLevel();

	// Lower the sensibility.
	void LowerSensibilityLevel();

	// Reload the configuration.
	bool ReloadConfiguration();

	// Scan the defined pixels until the popup is found, then launch the TryToCaptureTask.
	void ManualGrabTask();

	// Scan the defined pixels until the popup is found, then launch the TryToCaptureTask and stop it as soon as the popup is closed.
	void AutoGrabTask();

	// Check the defined pixels to determine if the popup is displayed.
	bool CheckPixels();

	// Try to grab the land.
	void TryToGrabTask();

	// Calculate the start sleep interval.
	void CalculateStartSleep();

	// Low level hook.
	static LRESULT CALLBACK LowLevelHook(int nCode, WPARAM wParam, LPARAM lParam);
};

#endif  // __GRAB_MANAGER_H__